<!DOCTYPE html>





<html class="theme-next gemini" lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="generator" content="Hexo 3.9.0">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.3.0">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/CNY32x32.png?v=7.3.0">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/CNY16x16.png?v=7.3.0">
  <link rel="mask-icon" href="/images/logo.svg?v=7.3.0" color="#222">

<link rel="stylesheet" href="/css/main.css?v=7.3.0">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.7.0">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '7.3.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":true},
    save_scroll: false,
    copycode: {"enable":true,"show_result":true,"style":null},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.xml',
    motion: {"enable":false,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    translation: {
      copy_button: '复制',
      copy_success: '复制成功',
      copy_failure: '复制失败'
    }
  };
</script>

  <meta name="description" content="打包命令在总结解压前，需要先了解打包命令，Linux的有些压缩格式是无法直接压缩目录的，需要用到tar命令进行打包成文件。 使用方法：tar -cf[v] 打包后的文件名 需要打包的目录名">
<meta name="keywords" content="linux">
<meta property="og:type" content="article">
<meta property="og:title" content="linux常用命令-压缩解压命令">
<meta property="og:url" content="localhost:4000/2019/08/17/linux常用命令-压缩解压命令/index.html">
<meta property="og:site_name" content="钟浩伟的个人博客">
<meta property="og:description" content="打包命令在总结解压前，需要先了解打包命令，Linux的有些压缩格式是无法直接压缩目录的，需要用到tar命令进行打包成文件。 使用方法：tar -cf[v] 打包后的文件名 需要打包的目录名">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2019-08-17T16:38:12.876Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="linux常用命令-压缩解压命令">
<meta name="twitter:description" content="打包命令在总结解压前，需要先了解打包命令，Linux的有些压缩格式是无法直接压缩目录的，需要用到tar命令进行打包成文件。 使用方法：tar -cf[v] 打包后的文件名 需要打包的目录名">
  <link rel="canonical" href="localhost:4000/2019/08/17/linux常用命令-压缩解压命令/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true,
    isPage: false,
    isArchive: false
  };
</script>

  <title>linux常用命令-压缩解压命令 | 钟浩伟的个人博客</title>
  








  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  <div class="container sidebar-position-left">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">钟浩伟的个人博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">欢迎光临</p>
      
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
      
      
      
        
        <li class="menu-item menu-item-home">
      
    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-tags">
      
    

    <a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-categories">
      
    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-archives">
      
    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a href="javascript:;" class="popup-trigger">
        
          <i class="menu-item-icon fa fa-search fa-fw"></i> <br>搜索</a>
      </li>
    
  </ul>

</nav>
  <div class="site-search">
    
  <div class="popup search-popup">
  <div class="search-header">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <div class="search-input-wrapper">
      <input autocomplete="off" autocorrect="off" autocapitalize="none"
             placeholder="搜索..." spellcheck="false"
             type="text" id="search-input">
    </div>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
  </div>
  <div id="search-result"></div>
</div>


  </div>
</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
            

          <div id="content" class="content page-post-detail">
            

  <div id="posts" class="posts-expand">
    

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="localhost:4000/2019/08/17/linux常用命令-压缩解压命令/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="钟浩伟">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/profile.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="钟浩伟的个人博客">
    </span>
      <header class="post-header">

        
          <h1 class="post-title" itemprop="name headline">linux常用命令-压缩解压命令

            
          </h1>
        

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              
                
              

              <time title="创建时间：2019-08-17 22:08:03" itemprop="dateCreated datePublished" datetime="2019-08-17T22:08:03+08:00">2019-08-17</time>
            </span>
          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/运维/" itemprop="url" rel="index"><span itemprop="name">运维</span></a></span>

                
                
              
            </span>
          

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="打包命令"><a href="#打包命令" class="headerlink" title="打包命令"></a>打包命令</h1><p>在总结解压前，需要先了解打包命令，Linux的有些压缩格式是无法直接压缩目录的，需要用到<code>tar</code>命令进行打包成文件。</p>
<p>使用方法：<code>tar -cf[v] 打包后的文件名 需要打包的目录名</code></p>
<a id="more"></a>

<p>选项: </p>
<ul>
<li><code>-c</code>打包</li>
<li><code>-f</code>指定文件名</li>
<li><code>-v</code>输出详细信息</li>
<li><code>-x</code>解包</li>
</ul>
<p>例如：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@ecs-s2-medium-2-linux-20190722215607 home]# tar -cf testDir.tar testDir</span><br><span class="line">[root@ecs-s2-medium-2-linux-20190722215607 home]# ls</span><br><span class="line">testDir  testDir.tar</span><br></pre></td></tr></table></figure>

<h1 id="几种压缩格式及命令"><a href="#几种压缩格式及命令" class="headerlink" title="几种压缩格式及命令"></a>几种压缩格式及命令</h1><h2 id="gz格式"><a href="#gz格式" class="headerlink" title=".gz格式"></a>.gz格式</h2><p>这种格式在Linux中用的最多，也最常见</p>
<h3 id="压缩文件命令"><a href="#压缩文件命令" class="headerlink" title="压缩文件命令"></a>压缩文件命令</h3><p><code>.gz</code>文件可以用<code>gzip</code> 命令进行压缩</p>
<h4 id="注意点"><a href="#注意点" class="headerlink" title="注意点"></a>注意点</h4><ol>
<li><code>gz</code>命令只能压缩文件，该命令无法压缩目录。</li>
<li><code>gz</code>压缩完成后不保存源文件</li>
</ol>
<h3 id="压缩目录"><a href="#压缩目录" class="headerlink" title="压缩目录"></a>压缩目录</h3><p>压缩目录有两种方法，因为gz命令是无法直接压缩目录的，所以要先对目录进行打包，打包成tar文件</p>
<h4 id="方法一：先打包，在压缩"><a href="#方法一：先打包，在压缩" class="headerlink" title="方法一：先打包，在压缩"></a>方法一：先打包，在压缩</h4><ol>
<li><p>先使用<code>tar -cf 打包后的文件名 需要打包的文件名</code>先把目录打成tar包</p>
</li>
<li><p>再用<code>gzip</code>将tar包压缩。</p>
</li>
</ol>
<h4 id="方法二：利用tar打包并压缩"><a href="#方法二：利用tar打包并压缩" class="headerlink" title="方法二：利用tar打包并压缩"></a>方法二：利用tar打包并压缩</h4><p>如果需要压缩目录，则需要用到<code>tar</code>命令，该命令将目录打包成文件同时进行压缩，压缩后的格式为<code>tar.gz</code></p>
<p>再复习下常用选项 </p>
<ul>
<li><code>-c</code>打包</li>
<li><code>-v</code>显示详细信息</li>
<li><code>-f</code>指定文件名</li>
<li><code>-z</code>打包同时压缩成.gz压缩包</li>
</ul>
<p>例如：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@ecs-s2-medium-2-linux-20190722215607 home]# tar -cvf testDir.tar testDir/ #打包某个目录</span><br><span class="line">testDir/</span><br><span class="line">[root@ecs-s2-medium-2-linux-20190722215607 home]# ls</span><br><span class="line">testDir  testDir.tar</span><br></pre></td></tr></table></figure>

<p>然后可用gz命令对该目录打包后的文件进行压缩</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@ecs-s2-medium-2-linux-20190722215607 home]# gzip testDir.tar </span><br><span class="line">[root@ecs-s2-medium-2-linux-20190722215607 home]# ls</span><br><span class="line">testDir  testDir.tar.gz</span><br></pre></td></tr></table></figure>

<p>如果觉得先打包再压缩有点麻烦，可以加入<code>-z</code>参数，在打包的同时进行压缩</p>
<p>例如：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@ecs-s2-medium-2-linux-20190722215607 home]# tar -zcf testDir.tar.gz testDir/</span><br><span class="line">[root@ecs-s2-medium-2-linux-20190722215607 home]# ls</span><br><span class="line">testDir  testDir.tar.gz</span><br><span class="line">[root@ecs-s2-medium-2-linux-20190722215607 home]#</span><br></pre></td></tr></table></figure>

<h3 id="解压缩文件"><a href="#解压缩文件" class="headerlink" title="解压缩文件"></a>解压缩文件</h3><p>使用<code>gunzip</code>或者<code>gzip -d</code>命令可以进行解压缩</p>
<h3 id="解压目录"><a href="#解压目录" class="headerlink" title="解压目录"></a>解压目录</h3><p>因为压缩目录有两种方法，同样解压也有两种方法：</p>
<h4 id="方法一：先解压，在进行解包"><a href="#方法一：先解压，在进行解包" class="headerlink" title="方法一：先解压，在进行解包"></a>方法一：先解压，在进行解包</h4><ol>
<li>先用<code>gunzip 压缩文件名</code>进行解压</li>
<li>再用<code>tar -xf t包名</code>进行解包</li>
</ol>
<h4 id="方法二：利用tar解包并解压"><a href="#方法二：利用tar解包并解压" class="headerlink" title="方法二：利用tar解包并解压"></a>方法二：利用tar解包并解压</h4><p>常见选项如下：</p>
<ul>
<li><code>-x</code>解包 （与<code>-c</code>对应）</li>
<li><code>-v</code>显示详细信息</li>
<li><code>-f</code>指定压缩文件</li>
<li><code>-z</code>解压缩</li>
</ul>
<p>例如：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@ecs-s2-medium-2-linux-20190722215607 home]# tar -xzvf testDir.tar.gz </span><br><span class="line">testDir/</span><br><span class="line">[root@ecs-s2-medium-2-linux-20190722215607 home]# ls</span><br><span class="line">testDir  testDir.tar.gz</span><br></pre></td></tr></table></figure>

<h4 id="使用tar命令的注意点"><a href="#使用tar命令的注意点" class="headerlink" title="使用tar命令的注意点"></a>使用tar命令的注意点</h4><p><code>-f</code>选项后面一定要加文件名，也就是如果你要把选项写在一起，请把<code>-f</code>放在最后面，像这样<code>-xzvf</code>或者<code>-czvf</code></p>
<h2 id="bz2格式"><a href="#bz2格式" class="headerlink" title=".bz2格式"></a>.bz2格式</h2><p>该格式是<code>.gz</code>的升级版，他的好处是压缩比非常惊人，常用来压缩大文件。</p>
<h3 id="压缩文件"><a href="#压缩文件" class="headerlink" title="压缩文件"></a>压缩文件</h3><p>使用<code>bzip2</code>进行压缩</p>
<ul>
<li>用法：<code>bzip  选项[-k] [文件]</code></li>
<li>选项：<code>-k</code>产生压缩文件后保留原文件</li>
<li>压缩后的格式：<code>.bz2</code></li>
</ul>
<h3 id="压缩目录-1"><a href="#压缩目录-1" class="headerlink" title="压缩目录"></a>压缩目录</h3><h4 id="方法一：先打包，在压缩-1"><a href="#方法一：先打包，在压缩-1" class="headerlink" title="方法一：先打包，在压缩"></a>方法一：先打包，在压缩</h4><ol>
<li>先使用<code>tar -cf 打包后的文件名 需要打包的文件名</code>先把目录打成tar包</li>
<li>再用<code>bzip</code>将tar包压缩。</li>
</ol>
<h4 id="方法二：利用tar打包并压缩-1"><a href="#方法二：利用tar打包并压缩-1" class="headerlink" title="方法二：利用tar打包并压缩"></a>方法二：利用tar打包并压缩</h4><p>如果你想在用<code>tar</code>命令打包的同时进行压缩，并且压缩后的格式为<code>.bz2</code>，那么需要加入选项<code>-j</code> （注意与<code>tar</code>压缩成<code>.gz</code>格式的<code>-z</code>选项进行区分）</p>
<p>例如：</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-attr">[root@ecs-s2-medium-2-linux-20190722215607 home]</span># <span class="selector-tag">tar</span> <span class="selector-tag">-cjf</span> <span class="selector-tag">testDir</span><span class="selector-class">.tar</span><span class="selector-class">.bz2</span> <span class="selector-tag">testDir</span></span><br><span class="line"><span class="selector-attr">[root@ecs-s2-medium-2-linux-20190722215607 home]</span># <span class="selector-tag">ls</span></span><br><span class="line"><span class="selector-tag">testDir</span>  <span class="selector-tag">testDir</span><span class="selector-class">.tar</span><span class="selector-class">.bz2</span></span><br></pre></td></tr></table></figure>

<h3 id="解压缩文件-1"><a href="#解压缩文件-1" class="headerlink" title="解压缩文件"></a>解压缩文件</h3><p>使用命令<code>bunzip2</code>就可以对<code>.bz2</code>文件进行解压缩</p>
<ul>
<li><p>使用方法：<code>bunzip2 选项[-k] [压缩文件名]</code></p>
</li>
<li><p>选项：<code>-k</code>解压缩后保留原文件</p>
</li>
</ul>
<p>例如：</p>
<figure class="highlight autoit"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root<span class="symbol">@ecs</span>-s2-medium<span class="number">-2</span>-linux<span class="number">-20190722215607</span> home]<span class="meta"># bunzip2 testDir.tar.bz2 </span></span><br><span class="line">[root<span class="symbol">@ecs</span>-s2-medium<span class="number">-2</span>-linux<span class="number">-20190722215607</span> home]<span class="meta"># ls</span></span><br><span class="line">testDir</span><br><span class="line">[root<span class="symbol">@ecs</span>-s2-medium<span class="number">-2</span>-linux<span class="number">-20190722215607</span> home]<span class="meta">#</span></span><br></pre></td></tr></table></figure>

<h3 id="解压缩目录"><a href="#解压缩目录" class="headerlink" title="解压缩目录"></a>解压缩目录</h3><h4 id="方法一：先解压，再解包"><a href="#方法一：先解压，再解包" class="headerlink" title="方法一：先解压，再解包"></a>方法一：先解压，再解包</h4><p>你可以先用<code>gunzip</code>进行解压文件，解压出来是个tar包，然后用用<code>tar -xf</code>进行解包即可</p>
<h4 id="方法二：利用tar解包并解压-1"><a href="#方法二：利用tar解包并解压-1" class="headerlink" title="方法二：利用tar解包并解压"></a>方法二：利用tar解包并解压</h4><p><code>tar -xjf</code>进行解包并进行解压缩</p>
<p>注意区分：解压<code>.gz</code>格式的tar包时用的是<code>-z</code>，解压<code>.bz2</code>格式tar包时用的是<code>-j</code></p>
<h2 id="gz-与-bz2用法比较"><a href="#gz-与-bz2用法比较" class="headerlink" title=".gz 与 .bz2用法比较"></a>.gz 与 .bz2用法比较</h2><table>
<thead>
<tr>
<th align="left">命令\格式</th>
<th align="center">.gz</th>
<th align="center">.bz2</th>
</tr>
</thead>
<tbody><tr>
<td align="left">压缩文件</td>
<td align="center">gzip</td>
<td align="center">bzip2</td>
</tr>
<tr>
<td align="left">压缩目录</td>
<td align="center">方法一：先用<code>tar -cf</code>进行打包，在用<code>gzip</code>进行压缩；方法二：直接用<code>tar -czf</code>进行压缩</td>
<td align="center">方法一：先用<code>tar -cf</code>进行打包，在用<code>bzip2</code>进行压缩；方法二：直接用<code>tar -cjf</code>进行压缩</td>
</tr>
<tr>
<td align="left">解压缩文件</td>
<td align="center">gunzip</td>
<td align="center">bunzip2</td>
</tr>
<tr>
<td align="left">解压缩目录</td>
<td align="center">方法一：先用<code>gunzip</code>进行解压，解压得到的文件是<code>.tar</code>包，在用 <code>tar -xf</code>进行解包；方法二：直接用<code>tar -xzf</code>进行解包并解压缩</td>
<td align="center">方法一：先用<code>bunzip2</code>进行解压，再用<code>tar -xf</code>进行解包；方法二：直接用<code>tar -xjf</code>进行解包并解压缩。</td>
</tr>
</tbody></table>
<h4 id="再次强调注意点："><a href="#再次强调注意点：" class="headerlink" title="再次强调注意点："></a>再次强调注意点：</h4><ol>
<li>如果你使用<code>tar -czf</code>或<code>tar -cjf</code>进行压缩目录，<code>f</code>后面要跟两个东西，一个是压缩后的文件名，一个是需要压缩的目录。类似这样<code>tar -cjf testDir.tar.gz testDir</code></li>
<li>如果你使用<code>tar -xzf</code>或<code>tar -xjf</code>进行解压缩目录，f之后只用跟需要解压的文件即可。类似这样<code>tar -xjf testDir.tar.bz2</code></li>
</ol>
<h2 id="zip格式"><a href="#zip格式" class="headerlink" title=".zip格式"></a>.zip格式</h2><p>.zip是windows和linux都支持的压缩格式</p>
<p>压缩后的格式为<code>.zip</code></p>
<h3 id="zip压缩命令"><a href="#zip压缩命令" class="headerlink" title="zip压缩命令"></a>zip压缩命令</h3><p>使用格式：<code>zip 选项[-r] [压缩后的文件名] [文件或目录]</code></p>
<ul>
<li>选项：<code>-r</code> 压缩目录</li>
</ul>
<p>与gz命令不同的是：可压缩目录，保留源文件</p>
<p>例如：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[root@ecs-s2-medium-2-linux-20190722215607 home]# zip  -r testDir.zip testDir</span><br><span class="line">  adding: testDir/ (stored 0%)</span><br></pre></td></tr></table></figure>

<p>该命令还会很人性化的提醒你压缩比。因为我这个是空目录，所以是0。</p>
<h3 id="zip解压缩命令"><a href="#zip解压缩命令" class="headerlink" title="zip解压缩命令"></a>zip解压缩命令</h3><p>使用<code>unzip</code>就可以解压缩.zip的压缩文件</p>
<p>例如：</p>
<figure class="highlight dts"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@ecs-s2-medium<span class="number">-2</span>-linux<span class="number">-20190722215607</span> home]<span class="meta"># unzip testDir.zip </span></span><br><span class="line"><span class="symbol">Archive:</span>  testDir.zip</span><br><span class="line"><span class="symbol">   creating:</span> testDir/</span><br></pre></td></tr></table></figure>


    </div>

    
    
    
      
  <div class="popular-posts-header">相关文章推荐</div>
  <ul class="popular-posts">
    <li class="popular-posts-item">
      
      
      <div class="popular-posts-title"><a href="\2019\08\16\Linux常见命令-帮助命令\" rel="bookmark">Linux常见命令-帮助命令</a></div>
      
    </li>
  
    <li class="popular-posts-item">
      
      
      <div class="popular-posts-title"><a href="\2019\08\16\Linux常见命令-用户管理命令\" rel="bookmark">Linux常见命令-用户管理命令</a></div>
      
    </li>
  
  </ul>


    
    <div>
      
      <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束感谢您的阅读,如有疑问，请联系<a href="mailto:610596547@qq.com">610596547@qq.com</a>-------------</div>
    
</div>
      
    </div>
        
      

      <footer class="post-footer">
          
            
          
          <div class="post-tags">
            
              <a href="/tags/linux/" rel="tag"># linux</a>
            
          </div>
        

        

          <div class="post-nav">
            <div class="post-nav-next post-nav-item">
              
                <a href="/2019/08/16/Linux常见命令-用户管理命令/" rel="next" title="Linux常见命令-用户管理命令">
                  <i class="fa fa-chevron-left"></i> Linux常见命令-用户管理命令
                </a>
              
            </div>

            <span class="post-nav-divider"></span>

            <div class="post-nav-prev post-nav-item">
              
                <a href="/2019/08/18/Linux常用命令-网络命令/" rel="prev" title="Linux常用命令-网络命令">
                  Linux常用命令-网络命令 <i class="fa fa-chevron-right"></i>
                </a>
              
            </div>
          </div>
        
      </footer>
    
  </div>
  
  
  
  </article>

  </div>


          </div>
          

        </div>
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">

          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image"
      src="/images/profile.jpg"
      alt="钟浩伟">
  <p class="site-author-name" itemprop="name">钟浩伟</p>
  <div class="site-description motion-element" itemprop="description"></div>
</div>
  <nav class="site-state motion-element">
      <div class="site-state-item site-state-posts">
        
          <a href="/archives/">
        
          <span class="site-state-item-count">44</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
    
      
      
      <div class="site-state-item site-state-categories">
        
          
            <a href="/categories/">
          
        
        
        
          
        
          
        
          
        
          
        
          
        
          
        
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">分类</span>
        </a>
      </div>
    
      
      
      <div class="site-state-item site-state-tags">
        
          
            <a href="/tags/">
          
        
        
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
        <span class="site-state-item-count">15</span>
        <span class="site-state-item-name">标签</span>
        </a>
      </div>
    
  </nav>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="https://github.com/XiaoZhong233" title="GitHub &rarr; https://github.com/XiaoZhong233" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
    
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="mailto:601596547@qq.com" title="E-Mail &rarr; mailto:601596547@qq.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
    
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="https://blog.csdn.net/weixin_41154636" title="CSDN &rarr; https://blog.csdn.net/weixin_41154636" rel="noopener" target="_blank"><i class="fa fa-fw fa-book"></i>CSDN</a>
      </span>
    
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="http://profile.zhonghaowei.xyz/" title="Profile &rarr; http://profile.zhonghaowei.xyz/" rel="noopener" target="_blank"><i class="fa fa-fw fa-address-card-o"></i>Profile</a>
      </span>
    
  </div>



        </div>
      </div>
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#打包命令"><span class="nav-number">1.</span> <span class="nav-text">打包命令</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#几种压缩格式及命令"><span class="nav-number">2.</span> <span class="nav-text">几种压缩格式及命令</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#gz格式"><span class="nav-number">2.1.</span> <span class="nav-text">.gz格式</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#压缩文件命令"><span class="nav-number">2.1.1.</span> <span class="nav-text">压缩文件命令</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#注意点"><span class="nav-number">2.1.1.1.</span> <span class="nav-text">注意点</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#压缩目录"><span class="nav-number">2.1.2.</span> <span class="nav-text">压缩目录</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#方法一：先打包，在压缩"><span class="nav-number">2.1.2.1.</span> <span class="nav-text">方法一：先打包，在压缩</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#方法二：利用tar打包并压缩"><span class="nav-number">2.1.2.2.</span> <span class="nav-text">方法二：利用tar打包并压缩</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#解压缩文件"><span class="nav-number">2.1.3.</span> <span class="nav-text">解压缩文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#解压目录"><span class="nav-number">2.1.4.</span> <span class="nav-text">解压目录</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#方法一：先解压，在进行解包"><span class="nav-number">2.1.4.1.</span> <span class="nav-text">方法一：先解压，在进行解包</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#方法二：利用tar解包并解压"><span class="nav-number">2.1.4.2.</span> <span class="nav-text">方法二：利用tar解包并解压</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#使用tar命令的注意点"><span class="nav-number">2.1.4.3.</span> <span class="nav-text">使用tar命令的注意点</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#bz2格式"><span class="nav-number">2.2.</span> <span class="nav-text">.bz2格式</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#压缩文件"><span class="nav-number">2.2.1.</span> <span class="nav-text">压缩文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#压缩目录-1"><span class="nav-number">2.2.2.</span> <span class="nav-text">压缩目录</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#方法一：先打包，在压缩-1"><span class="nav-number">2.2.2.1.</span> <span class="nav-text">方法一：先打包，在压缩</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#方法二：利用tar打包并压缩-1"><span class="nav-number">2.2.2.2.</span> <span class="nav-text">方法二：利用tar打包并压缩</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#解压缩文件-1"><span class="nav-number">2.2.3.</span> <span class="nav-text">解压缩文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#解压缩目录"><span class="nav-number">2.2.4.</span> <span class="nav-text">解压缩目录</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#方法一：先解压，再解包"><span class="nav-number">2.2.4.1.</span> <span class="nav-text">方法一：先解压，再解包</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#方法二：利用tar解包并解压-1"><span class="nav-number">2.2.4.2.</span> <span class="nav-text">方法二：利用tar解包并解压</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#gz-与-bz2用法比较"><span class="nav-number">2.3.</span> <span class="nav-text">.gz 与 .bz2用法比较</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#再次强调注意点："><span class="nav-number">2.3.0.1.</span> <span class="nav-text">再次强调注意点：</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#zip格式"><span class="nav-number">2.4.</span> <span class="nav-text">.zip格式</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#zip压缩命令"><span class="nav-number">2.4.1.</span> <span class="nav-text">zip压缩命令</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#zip解压缩命令"><span class="nav-number">2.4.2.</span> <span class="nav-text">zip解压缩命令</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      



    </div>
  </aside>
  <div id="sidebar-dimmer"></div>




      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love" id="animate">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">钟浩伟</span>
</div>


<div id="days"></div>
<div class="BbeiAn-info">
   	粤ICP备 -
    <a target="_blank" href="http://beian.miit.gov.cn" style="color:#f0d784"  rel="nofollow">粤ICP备19111001号-1</a> <!--a标签中增加nofollow属性，避免爬虫出站。-->| 
	<a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=" style="color:#f0d784;text-decoration:none;padding-left:30px;background:url(https://s1.ax1x.com/2018/09/29/ilmwIH.png) no-repeat left center" rel="nofollow">粤公网安备 粤ICP备19111001号-1</a>	  <!--这里将图标作为了背景，以使得能和后面的文字在同一行-->
</div>

<script>
function show_date_time(){
    window.setTimeout("show_date_time()", 1000);
    BirthDay=new Date("08/15/2019 22:40:14");
    today=new Date();
    timeold=(today.getTime()-BirthDay.getTime());
    sectimeold=timeold/1000
    secondsold=Math.floor(sectimeold);
    msPerDay=24*60*60*1000
    e_daysold=timeold/msPerDay
    daysold=Math.floor(e_daysold);
    e_hrsold=(e_daysold-daysold)*24;
    hrsold=setzero(Math.floor(e_hrsold));
    e_minsold=(e_hrsold-hrsold)*60;
    minsold=setzero(Math.floor((e_hrsold-hrsold)*60));
    seconds=setzero(Math.floor((e_minsold-minsold)*60));
    document.getElementById('days').innerHTML="<p>小破站已运行 "+daysold+" 天 "+hrsold+" 小时 "+minsold+" 分 "+seconds+" 秒</p>";
}
function setzero(i) {
    if (i<10) {
        i="0" + i
    };
    return i;
}
show_date_time();
</script>

        








        
      </div>
    </footer>
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>

    

  </div>

  
  <script src="/lib/jquery/index.js?v=3.4.1"></script>

<script src="/js/utils.js?v=7.3.0"></script>

<script src="/js/schemes/pisces.js?v=7.3.0"></script>



<script src="/js/next-boot.js?v=7.3.0"></script>




  















  <script src="/js/local-search.js?v=7.3.0"></script>










<script>
if (document.querySelectorAll('pre.mermaid').length) {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/mermaid@8/dist/mermaid.min.js', () => {
    mermaid.initialize({
      theme: 'default',
      logLevel: 3,
      flowchart: { curve: 'linear' },
      gantt: { axisFormat: '%m/%d/%Y' },
      sequence: { actorMargin: 50 }
    });
  }, window.mermaid);
}
</script>




  

  

  


  
  <script src="/js/scrollspy.js?v=7.3.0"></script>
<script src="/js/post-details.js?v=7.3.0"></script>



  
  <script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>
  
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"log":false,"model":{"jsonPath":"/live2dw/assets/assets/hijiki.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":false}});</script></body>
</html>
